package com.zjj.lbw.guava.collection;

import com.google.common.collect.HashMultiset;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.junit.Test;

import java.util.HashMap;
import java.util.Map;

/**
 * @author zhanglei.zjj
 * @description TODO
 * @date 2023/7/16 17:13
 */
public class TestGuavaCollection {
    @Test
    public void test1() {
//        // 传统写法
        String[] words = {"关注", "guava集合", "zjj", "大宗师苦荷", "zjj", "guava集合"};
//        Map<String, Integer> counts = new HashMap<String, Integer>();
//        for (String word : words) {
//            Integer count = counts.get(word);
//            if (count == null) {
//                counts.put(word, 1);
//            } else {
//                counts.put(word, count + 1);
//            }
//        }
//
//        Integer count = counts.get("影子");
//        System.out.println("count:" + count);

        // 使用guava Multiset 写法
        HashMultiset<@Nullable Object> multiset = HashMultiset.create();

        for (String word : words) {
            multiset.add(word);
        }


        Integer count = multiset.count("影子");
        System.out.println("count:" + count);
    }
}
